﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using Microsoft.Phone.Controls;
using System.Device.Location;
using Sisocana.PhoneApp.MobileServices;

namespace Sisocana.PhoneApp.Views
{
    public partial class LastPage : PhoneApplicationPage, INotifyPropertyChanged
    {
        private string _resultMessage = "Sending...";

        public string ResultMessage {
            get { return _resultMessage; }
            set {
                _resultMessage = value;
                NotifyPropertyChanged("ResultMessage");
            }
        }

        public LastPage() {
            InitializeComponent();
            Message.DataContext = this;
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var client = new MobileServicesClient();
            client.SendHelpRequestCompleted += (s, ea) =>
            {
                if (ea.Result)
                    ResultMessage = Assets.Resources.ApplicationStrings.SubmitSuccess;
                else
                    ResultMessage = Assets.Resources.ApplicationStrings.SubmitError;
            };
            client.SendHelpRequestAsync(HelpRequestForm.Message);
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e){
            InfoPage.AlreadyVisited = true;
            base.OnBackKeyPress(e);
        }

        private void btnGoBack_Click(object sender, RoutedEventArgs e) {
            InfoPage.AlreadyVisited = true;
            NavigationService.GoBack();
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}